package com.door.erp.sevice.base;

import java.io.Serializable;
import java.util.List;
import java.util.Map;

import com.door.erp.dao.base.GenericDao;
import com.door.erp.pager.Pager;

/**
 * Service层通用方法实现
 * @author yangxuelin
 */
public abstract class GenericServiceImpl<T, PK extends Serializable> implements
		GenericService<T, PK> {
	
	//protected GenericDao<T, PK> dao;
	
	public abstract GenericDao<T, PK> getDao();

	@Override
	public void add(T object) {
		getDao().add(object);		
	}

	@Override
	public void delete(T object) {
		getDao().delete(object);		
	}

	@Override
	public void delete(PK id) {
		getDao().delete(id);
	}

	@Override
	public void modify(T object) {
		getDao().modify(object);		
	}

	@Override
	public T getObject(PK id) {
		return getDao().get(id);
	}
	

	@Override
	public List<T> getAll(String hql) {
		return getDao().getAll(hql);
	}
	
	@Override
	public List<T> getAll(final Pager pager) {
		return getDao().getAll(pager.getStartRow(), pager.getNumPerPage());
	}

	@Override
	public List<T> getAll(String hql, Object... values) {
		return getDao().getAll(hql, values);
	}

	@Override
	public List<T> getAll(String hql, Object[] params, final Pager pager) {
		return getDao().getAll(hql, params, pager.getStartRow(), pager.getNumPerPage());
	}

	@Override
	public int getCount(String hql, Object... params) {
		return getDao().getCount(hql, params);
	}
	
	@Override
	public List<T> getAll() {
		return getDao().getAll();
	}

	@Override
	public List<T> getAll(Map<String, Object> params) {
		return getDao().getAll(params);
	}

	@Override
	public List<T> getAll(Map<String, Object> params, final Pager pager) {
		        pager.setTotalCount(getDao().getCount(params));
		return getDao().getAll(params, pager.getStartRow(), pager.getNumPerPage());
	}
	
	@Override
	public int getCount() {
		return getDao().getCount();
	}
	
	@Override
	public int getCount(Map<String, Object> params) {
		return getDao().getCount(params);
	}

	@Override
	public Integer executeUpdateByQuery(String sql, Object[] params) {
		return getDao().executeUpdateByQuery(sql, params);
	}

}
